<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ page isELIgnored="false" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html>

<head>
  <link href="<s:url value="/resources"/>/css/style_new.css" rel="stylesheet" type="text/css" />
<link href="<s:url value="/resources"/>/css/main_new.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/cupertino/jquery-ui.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.multiselect.css" />
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script>  
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/grid.locale-cn.js"></script> 
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.form.js"></script>
<style>
html,body {
	margin: 0;
	padding: 0;
	font-size: 85%;
}
</style>
<script >
    
     var qieye = 0;
$(function(){
	$("#yind").button();
    $("#chax").button(); 
    $("#excel").button();
	$("#excel").hide();
    $("#reset").button();
        
    loadTab(0);
    //queryNum();
    
    //日期控件处理
    $( "#datepicker" ).datepicker($.datepicker.regional[ "zh-CN" ]);
    $( "#datepicker1" ).datepicker($.datepicker.regional[ "zh-CN" ]);
 
	function loadTab(i){	
		if(i==0){
			loadBdxx(i);
		}else{
			loadYdxx(i);
		}
  		$("#myTab"+i).jqGrid('setGridHeight','300px');
  	}  
	

    $( "#tabs" ).tabs({
		    select: function(event, ui) {
		    var i =ui.index;	    
		    if(i==''){
		    i="0";
		    }
		    qieye = i;
		    loadTab(i);
		    //$("#myTab"+qieye).jqGrid('setGridParam',{url:'findVerifyHtxxList.action?index='+qieye,mtype:'post',page:1}).trigger("reloadGrid");
		   // alert("aa");
		    //jQuery("#myTab1").jqGrid('hideCol',["Verify"]);
		        
            //return false;
  		  }
		
	});
	
	
 });
  

	

  
  
  function loadBdxx(i){
      $("#myTab"+i).jqGrid({      
    url:'findxieslist?mmlx=61&index='+i,  
    datatype: 'json',
    mtype: 'post',         
   	colNames:['操作','协商号','出卖人','买受人','煤种','品种','价格类型','价格','报单数量','应单数量','隶属行业','报单日期','当前状态','yingdbh','baodr'],
   	colModel:[ 
   	    {name:'Verify',index:'id',width:60,align:"center",sortable:false},
   	    {name:'baodbh',index:'baodbh', width:90},
   	    {name:'baodrdwmc',index:'baodrdwmc', width:150},
   		{name:'yinddrdwmc',index:'yinddrdwmc', width:150},
   		{name:'meizmc',index:'meizmc', width:40 },	
   		{name:'pinzmc',index:'pinzmc', width:40 },
   	    {name:'jiaglxmc',index:'jiaglxmc', width:60 },
   		{name:'danj',index:'danj', width:40 },
   		{name:'shul',index:'shul', width:60 },
   		{name:'yingdsl',index:'yingdsl', width:60 },
   		
   		 
   		{name:'lismc',index:'lismc', width:60 },
   		{name:'baodsj',index:'baodsj', width:65},
   		{name:'danjzt',index:'danjzt', width:150,formatter: "select", editoptions:{value:"0:发起协商;1:报单方确认;2:应单方确认;3:中心已审核;4:已撤销"}  },
   		{name:'yingdbh',index:'yingdbh',   hidden:true  },
   		{name:'baodr',index:'baodr',   hidden:true  }
   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'baodbh' 
         },    	
   	rowNum:10,

   	rowList:[10,20,30],     	
   	pager: '#pager'+i,   	
   	rownumbers: true,   	 
    viewrecords: true,
    //multiselect: sign,
    sortorder: 'desc',  
    altRows:true,  
	//caption: "报单列表",
	gridComplete:function()
	{ //在此事件中循环为每一行添加修改和删除链接 
		var ids=jQuery("#myTab"+i).jqGrid('getDataIDs'); 	
		for(var j=0; j<ids.length; j++)
		{ 
			var id=ids[j];	
			 var rowData = jQuery("#myTab"+qieye).jqGrid("getRowData", id);  
			 
			if(rowData.danjzt==4){
			//alert("11")
			}
			else{
				verify ="<a href='#' style='color:#f60' onclick='Verify("+ id +")'>协商</a>&nbsp;|&nbsp;<a href='#' style='color:#f60' onclick='selectx("+ id +")'>撤销</a>";	
				jQuery("#myTab"+i).jqGrid('setRowData',ids[j], { Verify: verify }); 
			}
			
		} 
	} 	
  });
  }
 

  function loadYdxx(i){
      $("#myTab"+i).jqGrid({      
    	    url:'findxieslist?mmlx=51&index='+i,  
    	    datatype: 'json',
    	    mtype: 'post',         
    	   	colNames:['操作','协商号','出卖人','买受人','煤种','品种','价格类型','价格','报单数量','应单数量','隶属行业','报单日期','当前状态','yingdbh','baodr'],
    	   	colModel:[ 
    	   	    {name:'Verify',index:'id',width:60,align:"center",sortable:false},
    	   	    {name:'baodbh',index:'baodbh', width:90},
    	   	    {name:'baodrdwmc',index:'baodrdwmc', width:150},
    	   		{name:'yinddrdwmc',index:'yinddrdwmc', width:150},
    	   		{name:'meizmc',index:'meizmc', width:40 },	
    	   		{name:'pinzmc',index:'pinzmc', width:40 },
    	   	    {name:'jiaglxmc',index:'jiaglxmc', width:60 },
    	   		{name:'danj',index:'danj', width:40 },
    	   		{name:'shul',index:'shul', width:60 },
    	   		{name:'yingdsl',index:'yingdsl', width:60 },
    	   		
    	   		 
    	   		{name:'lismc',index:'lismc', width:60 },
    	   		{name:'baodsj',index:'baodsj', width:65},
    	   		{name:'danjzt',index:'danjzt', width:150,formatter: "select", editoptions:{value:"0:发起协商中;1:报单方确认;2:应单方确认;3:中心已审核;4:已撤销"} },
    	   		{name:'yingdbh',index:'yingdbh',   hidden:true  },
    	   		{name:'baodr',index:'baodr',   hidden:true  }
    	   		
    	   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'baodbh'
         },    	
   	rowNum:10,
   	rowList:[10,20,30],     	
   	pager: '#pager'+i,   	
   	rownumbers: true,   	 
    viewrecords: true,
    //multiselect: sign,
    sortorder: 'desc',  
    altRows:true,  
	//caption: "报单列表",
	gridComplete:function()
	{ //在此事件中循环为每一行添加修改和删除链接 
		var ids=jQuery("#myTab"+i).jqGrid('getDataIDs');
	
		for(var j=0; j<ids.length; j++)
		{ 
			var id=ids[j];	
			if(rowData.danjzt==4){
				//alert("11")
				}
				else{
			verify ="<a href='#' style='color:#f60' onclick='select("+ id +")'>协商</a>&nbsp;|&nbsp;<a href='#' style='color:#f60' onclick='selectx("+ id +")'>撤销</a>";							
			jQuery("#myTab"+i).jqGrid('setRowData',ids[j], { Verify: verify }); 
				}
		} 
	} 	
  });
  }
  
  
  function openwindow(url){
    var sheight = screen.height-70;
    var swidth = screen.width-10;
    var winoption ="dialogHeight:"+sheight+"px;dialogWidth:"+ swidth +"px;status:yes;scroll:yes;resizable:yes;center:yes";
    var result=window.showModalDialog(url,window,winoption);
    if(result ==1){
    	if (qieye==0){
   		 reloadYdxx(); 	
   	} 
   	if (qieye==1){
   		jQuery("#myTab1").trigger("reloadGrid"); 
  	} 
     }
    return result;  
}
  
  function reloadYdxx(){
   window.location.href="<%=request.getContextPath()%>/gpjy/guapxslist";
}
  
   function Verify(id) { //单击修改链接的操作 
   if(id.id!=undefined){
	   var rowData = jQuery("#myTab0").jqGrid("getRowData", id.id);  
	// alert(rowData.maimlx);
	if (rowData.baodr==${userid}){
  openwindow('<%=path %>/gpjy/bdxgInfo?bdbh='+id.id+'&yingdbh='+rowData.yingdbh);
	}else{
		 openwindow('<%=path %>/gpjy/gpydMsryd?lx=3&yingdbh='+rowData.yingdbh);
		//bdxg4mfInfo?bdbh=BG1T1407020003&yingdbh=YG0T1406240015
	}
    }else{
    var bdbh = id.item(1).cells.item(3).innerHTML;	
	openwindow('<%=path %>/gpjy/gpydMsryd?bdbh='+bdbh+'&lx=1' );
    }
 
}
  // 查询
function search(){   
  var formdata = $("#form1").serialize(); 
//alert(formdata); 
  $("#myTab"+qieye).jqGrid('setGridParam',{url:'findydbdlist?'+formdata+'&mmlx=6&index='+qieye,mtype:'post',page:1}).trigger("reloadGrid"); 
 
  queryNum();
 
}

 
 function select(id) { //单击修改链接的操作 
	   if(id.id!=undefined){
		   var rowData = jQuery("#myTab1").jqGrid("getRowData", id.id);  
		// alert(rowData.maimlx);
		if (rowData.baodr==${userid}){
	  openwindow('<%=path %>/gpjy/bdxg4mfInfo?bdbh='+id.id+'&yingdbh='+rowData.yingdbh);
		}else{
			 openwindow('<%=path %>/gpjy/gpydCmryd?lx=3&yingdbh='+rowData.yingdbh);
			//bdxg4mfInfo?bdbh=BG1T1407020003&yingdbh=YG0T1406240015
		}
	    }else{
	    var bdbh = id.item(1).cells.item(3).innerHTML;	
		openwindow('<%=path %>/gpjy/gpydMsryd?bdbh='+bdbh+'&lx=1' );
	    }
	 
	}
 function selectx(id) { //单击查询链接的操作 
	   if(id.id!=undefined){
		   var rowData = jQuery("#myTab"+qieye).jqGrid("getRowData", id.id);  
		// alert(rowData.maimlx);
		var url = "<s:url value="/"/>/gpjy/xiugxszt?zt=14&ydbh="+rowData.yingdbh+"&bdbh="+rowData.baodbh;
		 if(confirm("确定要撤销此协商交易吗？")){
		$("#form1").ajaxSubmit({
			url : url,
			type : 'post',
			success : function(data) {
				var json = eval('(' + data + ')');
				if (json.result == 1) {
					alert("操作成功！");
					  $("#myTab"+qieye).trigger("reloadGrid"); 
				} else {
					alert("操作失败！");
				}
			}
		});
		}
	   }
}


function queryNum(){   
  var formdata = $("#form1").serialize(); 
  $.post("<%=path%>/htgl/findVerifyHtxxListNum.action",formdata,function(data,textStatus)
  {
  
  var json = eval('(' + data + ')');

  var re=/(\d{1,3})(?=(\d{3})+(?:$|\.))/g;
if (json[0].shul !="")
{
  // alert("价格范围："+json[0].jiag + "  总数量："+json[0].shul+"  总金额："+json[0].jine);
   $("#queryNum").html("价格范围："+json[0].jiag + "元/吨  总数量："+json[0].shul.toString().replace(re,"$1,")+"吨  总金额："+json[0].jine.toString().replace(re,"$1,")+"元");
 }
  });
  
}

function txt_onblur(i) {
            if (!event.srcElement.value) {
                event.srcElement.value = '0';
            }
           
            if (isNaN(temp)) {
                $("#"+i).val(0);                
            } 
        }
        
        //重置
			function resetSearch(){
			   $('#list_search  input[type=text]').val('');
			   $('#list_search select').val('-1');
			 }
        //导出excel
        function dc_excel(){ 
        var formdata = $("#form1").serialize(); 
	form1.action="<%=path%>/htgl/findVerifyHtxxList_excel.action?index="+qieye;
	form1.method = "post";
	form1.submit();
	}
	</script>

</head>

<body>
	<div class="container">
  <div class="containerbox">
   
    <div class="search mt10" id="list_search">
    <form id="form1" method="post">
    <table width="90%" border="0" cellspacing="0" cellpadding="0" class="search-table">
  <tr>
    <td align="left" valign="middle" class="search-table-300"><table border="0" cellspacing="0" cellpadding="0" class="search-table-300">
  <tr>
    <td align="right" class="pr10 search-table-70">协商编号</td>
    <td align="left"><input name="aa" type="text" class="form-textbox" style="width: 200px;" /></td>
  </tr>
</table></td>
    <td align="left" valign="middle" class="search-table-300"><table border="0" cellspacing="0" cellpadding="0" class="search-table-300">
  <tr>
    <td align="right" class="pr10 search-table-70">煤种</td>
    <td align="left"><select name="bb" class="form-textbox" style="width: 200px;">
      <option value="-1" selected>==请选择==</option>
                   <c:forEach var="mz" items="${meiz}">
                   <option value="${mz.diccode}">
                   ${mz.dicname}
                   </option>
                   </c:forEach>
                 </select>
                 
                 </td>
  </tr>
</table></td>
    <td align="left" valign="middle"><table border="0" cellspacing="0" cellpadding="0" class="search-table-300">
  <tr>
    <td align="right" class="pr10 search-table-70">品种</td>
    <td align="left"><select name="cc" class="form-textbox" style="width: 200px;">
      <option value="-1" selected>==请选择==</option>
                   <c:forEach var="pz" items="${pinz}">
                   <option value="${pz.diccode}">
                   ${pz.dicname}
                   </option>
                   </c:forEach>
                 </select></td>
  </tr>
</table></td>
  </tr>
  <tr>
    <td align="left" valign="middle"><table border="0" cellspacing="0" cellpadding="0" class="search-table-300">
  <tr>
    <td align="right" class="pr10 search-table-70">出卖人</td>
    <td align="left"><input name="oo" type="text" class="form-textbox" style="width: 200px;" /></td>
  </tr>
</table></td>
    <td align="left" valign="middle"><table border="0" cellspacing="0" cellpadding="0" class="search-table-300">
  <tr>
    <td align="right" class="pr10 search-table-70">发货单位</td>
    <td align="left"><input name="ee" type="text" class="form-textbox" style="width: 200px;" /></td>
  </tr>
</table></td>
    <td align="left" valign="middle"><table border="0" cellspacing="0" cellpadding="0" class="search-table-300">
  <tr>
    <td align="right" class="pr10 search-table-70">收货单位</td>
    <td align="left"><input name="ff" type="text" class="form-textbox" style="width: 200px;" /></td>
  </tr>
</table></td>
  </tr>
  <tr>
    
    <td align="left" valign="middle"><table border="0" cellspacing="0" cellpadding="0" class="search-table-300">
  <tr>
    <td align="right" class="pr10 search-table-70">买受人</td>
    <td align="left"><input name="xx" type="text" class="form-textbox" style="width: 200px;" /></td>
  </tr>
</table></td>
    <td align="left" valign="middle"><table border="0" cellspacing="0" cellpadding="0" class="search-table-300">
  <tr>
    <td align="right" class="pr10 search-table-70">报单日期</td>
    <td align="left"><input name="gg" type="text" class="form-textbox" style="width: 93px;"  id="datepicker"/>--
    <input name="hh" type="text" class="form-textbox" style="width: 93px;"  id="datepicker1"/></td>
  </tr>
</table></td>
<td align="left" valign="middle"><table border="0" cellspacing="0" cellpadding="0" class="search-table-300">
  <tr>
    <td align="right" class="pr10 search-table-70">价格</td>
    <td align="left"><input name="ii" type="text" class="form-textbox" style="width: 93px;" onKeyUp="this.value=this.value.replace(/\D/g,'');" />--
    <input name="jj" type="text" class="form-textbox" style="width: 93px;" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
  </tr>
</table></td>
  </tr>
   <tr>
    <td align="left" valign="middle" colspan="3"><table border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <td align="right" class="pr10 search-table-70">&nbsp;</td>
    <td align="left"><input name="" type="button" class="form-button-query form-button" value="查询" onclick="search();"/>
    <input name="" type="button" class="form-button-reset form-button" value="重置"  onclick="resetSearch();"/></td>
  </tr>
</table></td>
  </tr>
    </table>
</form></div>
			
   <div id="tabs">
			<ul>
				<li><a href="#tabs-0">买方发起协商</a></li>
				<li><a href="#tabs-1">卖方发起协商</a></li>
				<li id="queryNum"  style="float:right; vertical-align: bottom; line-height:20px; top: 3px;"></li>
			</ul>
			<div id="tabs-0">
				<table id="myTab0" class="scroll" cellpadding="0" cellspacing="0"  ></table>
				<div id="pager0" class="scroll"></div>
				<div id="message0" class="scroll"></div>
			</div>
			<div id="tabs-1">
				<table id="myTab1" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager1" class="scroll"></div>
				<div id="message1" class="scroll"></div>
			</div>

		</div>

		<div id="dialog-confirm" title="是否确认？"></div>
    
  </div>
</div> 
</body>
</html>
